import { State } from "../GameInterferce";
import ConcreteState from "./ConcreteState";
import { Game } from "./Game";

// 上下文类
class Context {
    private state: State | null;
    private args: GOBERTS.ActionArgs;
    public stepIndex: number;
    public game: Game;

    constructor(args: GOBERTS.ActionArgs, game: Game) {
        this.state = new ConcreteState.ConcreteClickCoin();
        this.args = args;
        this.stepIndex = 0;
        this.game = game;
    }

    sendData(data: string): void {
        this.args.SDK.sendData(data).then().catch(err => {
            this.args.SDK.log.error('send Collide fail, roomId:' + this.args.roomId + 'err:' + err);
        });
    }

    setState(state: State | null): void {
        this.state = state;
    }

    request(): void {
        this.state?.handle(this);
    }
}

export default Context